<link href="<?php echo URL::base() ?>media/vendor/css/ui-lightness/jquery-ui-1.10.4.custom.css" rel="stylesheet">
<script src="<?php echo URL::base() ?>media/vendor/js/jquery-1.10.2.js"></script>
<script src="<?php echo URL::base() ?>media/vendor/js/jquery-ui-1.10.4.custom.js"></script>
<script src="<?php echo URL::base() ?>media/vendor/js/jquery.ui.datepicker-zh-TW.js"></script>
<style>
    .myborder , .myborder th , .myborder td{border: 2px solid #ffffff;}
    .control-label{ display:inline-block; width:80px; text-align:right; margin-right:10px;}
    .table1 thead tr td,.table1 tbody tr td{ text-align:center;}
    .content-table{
        overflow: auto;
        width:100%;
        max-height: 500px;
    }
    .content-table table{
        width:1300px;
    }
</style>
<script type="text/javascript">
    $(document).ready(function(){
        $('.table1 > tbody > tr:odd').css("background-color","#f5f5f5");
    })
</script>
<form method='get' action='<? echo URL::site() ?>bymaterial/select'>
    <div class="control-group">
        <label class="control-label" >时间类型:</label>
        <select name='date_type' class=" date_type" id="date_type" style="width:100px;">
            <option value="bymaterial_date">借料时间</option>
            <option value="plan_return_date">预计归还时间</option>
            <option value="real_return_date">实际归还时间</option>
        </select>
        <input type='text' style="width:164px;" name='date_from' class=" datepicker" id="date_from" > ~
        <input type='text' name='date_to' style="width:164px;" id='date_to' class=" datepicker" >
    </div>
    <div class="control-group">
        <label class="control-label" >单据状态:</label>
        <select name='use_type' class="use_type" id="use_type" style="width:180px;">
            <option value="2">全部</option>
            <option value="0">待归还</option>
            <option value="1">已归还</option>
        </select>
        <label class="control-label" >sku:</label>
        <input type='text' style="width:164px;" name='sku' id='sku'>

    </div>
    <div class="control-group">
        <label class="control-label" >借料人:</label>
        <input type='text' style="width:164px;" name='username' id='username'>
    </div>
    <div class="control-group">
        <label class="control-label"></label>
        <input type='submit' class="btn btn-info" value='查询'>
    </div>

</form>
<div class="content-table">
    <table class="table table1 table-bordered myborder ">
        <thead class="table-fixedtd">
        <tr style="background-color:#4EA392; font-weight:bold; color:#ffffff; width: 1400px">
            <th>借料单id</th>
            <th>借料人</th>
            <th>借料原因</th>
            <th>借料日期</th>
            <th>sku</th>
            <th>sku名称</th>
            <th>借出数量</th>
            <th>实际库存量</th>
            <th>预计归还日期</th>
            <th>实际归还日期</th>
            <th>实际归还备注</th>
            <th>录入人</th>
            <th>录入日期</th>
            <th>归还备注</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        <?php if(isset($values)):
            foreach($values as $value):?>
                <tr>
                    <td><?php echo $value['id'];?></td>
                    <td><?php echo $value['bymaterial_username'];?></td>
                    <td><?php echo $value['bymaterial_renmark'];?></td>
                    <td><?php echo $value['bymaterial_date'];?></td>
                    <td><?php echo $value['sku'];?></td>
                    <td><?php echo $value['sku_name'];?></td>
                    <td><?php echo $value['num'];?></td>
                    <td><?php echo $value['real_num'];?></td>
                    <td><?php echo $value['plan_return_date'];?></td>
                    <td><?php echo $value['real_return_date'];?></td>
                    <td><?php echo $value['real_return_remark'];?></td>
                    <td><?php echo $value['register_username'];?></td>
                    <td><?php echo $value['add_time'] ;?></td>
                    <td><?php if($value['status']==0):?>
                    <input type="text" style="width:100px;" name='return_remark' id='return_remark' class="return_remark">
                    <?php endif;?></td>
                    <td><?php if($value['status']==0):?><input type="button" value="确认归还" class="return_button">
                        <?php endif;?></td>

                </tr>
            <?php endforeach;endif;?>
        </tbody>
    </table>

    <?php if(isset($pagination))echo $pagination;?>
</div>
<div style="text-align: center"><?php echo "总共".isset($num)&&!empty($num)?$num:''."条数据";?></div>
<script type="text/javascript">
    $(function(){

        $("#date_from").val('<?php echo isset($date_from)?$date_from:''?>');
        $("#date_to").val('<?php echo isset($date_to)?$date_to:''; ?>');
        $("#sku").val('<?php echo isset($sku)?$sku:''; ?>');
        $("#username").val('<?php echo isset($username)?$username:''; ?>');
        $("#use_type").val('<?php echo isset($use_type)?$use_type:''; ?>');
        $("#date_type").val('<?php echo isset($date_type)?$date_type:'bymaterial_date'; ?>');

        $.datepicker.setDefaults({ dateFormat: 'yy-mm-dd' });
        $("#date_from").datepicker({
            onSelect:function(dateText,inst){
                $("#date_to").datepicker("option","minDate",dateText);
            }
        });
        $("#date_to").datepicker({
            onSelect:function(dateText,inst){
                $("#date_from").datepicker("option","maxDate",dateText);
            }
        });

        //确认归还按钮
        $(".return_button").click(function(){
            var byid = $(this).parents('tr').children('td').eq(0).text();
            var return_remark = $.trim($(this).parents('tr').children('td').eq(13).find(".return_remark").val());
            if(return_remark==''){
                alert('确认归还备注不能为空');return false;
            }
            $.get(
                "<?php echo URL::base() ?>bymaterial/updatereturn",
                {return_remark:return_remark,byid:byid},
                function(data){

                    if(data=='ok'){
                        alert('确认归还提交成功');


                    }else{
                        alert(data);
                    }
                });
            $(this).hide();

        });
    });

</script>
